import { createRouter, createWebHistory } from 'vue-router'
import routes from './routes'

import userUserStore from '../store/modules/user'

// 用户保存 user 的 store 对象
let userStore: any

const router = createRouter({
    history: createWebHistory(),
    routes
})
router.beforeEach((to) => {
    document.title = to.meta.title as string

    if (!userStore) {
        userStore = userUserStore()
    }
    if(to.meta?.needPermission) {
        if(!userStore.token) {
            return '/login'
        }
    }
})

// 权限拦截

export default router